package controller;

import dao.BaseDao;
import entity.Car;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CarMenageMentServlet extends HttpServlet {
    BaseDao baseDao=new BaseDao();
    Car car=new Car();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        car.setCheZhu(req.getParameter("idNumBer"));
        car.setChePaiHao(req.getParameter("phoneNum"));
        car.setShouJia(req.getParameter("carType"));
        addCar();
    }

    public void addCar(){
        Object [] carinfo={car.getChePaiHao(),car.getShouJia(),car.getCheZhu()};
        baseDao.executeUpdate("INSERT INTO carinfo (ChePaiHao,ShouJia,CheZhu )VALUES(?,?,?);",carinfo);
    }
}
